package servlet;

import entity.User;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
@WebServlet("/el")
public class ElServlet extends HttpServlet {
    @Override
    protected void service(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {


        req.setAttribute("key1",123);
        req.getSession().setAttribute("key1","session");
        getServletContext().setAttribute("key1","application");




        req.setAttribute("key2","value2");

        req.setAttribute("key3", new User(1, "lisi", "321"));

        String[] arr = {"a1", "b1", "c1"};
        req.setAttribute("key4",arr);

        List<User> users = new ArrayList<>();
        users.add(new User(1, "admin", "admin"));
        users.add(new User(2, "wangwu", "123"));
        req.setAttribute("key5",users);

        Map<String, User> map = new HashMap<>();
        map.put("a1", new User(1, "admin", "admin"));
        map.put("a2", new User(2, "wangwu", "123"));
        req.setAttribute("key6",map);

        req.getRequestDispatcher("el.jsp").forward(req, resp);
    }
}
